package com.gpframework.module.ctn.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.ctn.domain.GpReceiptGoods;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @ClassName GpReceiptGoodsReq
 * @Author gpframework
 * @Date 2024-01-08
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpSupplierSummaryReq extends BaseReq {
    private static final long serialVersionUID = 1L;

     @ApiModelProperty("进仓日期")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date receiptDate;
    @ApiModelProperty("进仓单号")
    private String receiptNo;
    @ApiModelProperty("供应商名称")
    private String supplier;
    @ApiModelProperty("供应商号码")
    private String supplierTel;
    @ApiModelProperty("客户名")
    private String customer;
    @ApiModelProperty("客户电话号码")
    private String customerTel;
    @ApiModelProperty("包号")
    private String packNo;
    @ApiModelProperty("货柜序货柜序号")
    private String agentCtnNo;
    @ApiModelProperty("是否扣货:0否 1是")
    private String holdOrNot;
    @ApiModelProperty("扣货国内放货日期")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date chinaReleaseDate;
    @ApiModelProperty("尼仓库放货日期")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date nigeriaReleaseDate;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpReceiptGoods> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
        }

        if (StringUtils.isNotBlank(this.getReceiptNo())){
            lqw.eq(alias+"receipt_no" ,this.getReceiptNo());
        }
        if (this.getReceiptDate() != null){
            lqw.apply("DATE_FORMAT(gp.receipt_date, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getReceiptDate()) + "'");
        }
        if (StringUtils.isNotBlank(this.getSupplier())){
            lqw.eq(alias+"supplier" ,this.getSupplier());
        }
        if (StringUtils.isNotBlank(this.getSupplierTel())){
            lqw.eq(alias+"supplier_tel" ,this.getSupplierTel());
        }
        if (StringUtils.isNotBlank(this.getCustomer())){
            lqw.eq(alias+"customer" ,this.getCustomer());
        }
        if (StringUtils.isNotBlank(this.getCustomerTel())){
            lqw.eq(alias+"customer_tel" ,this.getCustomerTel());
        }
        if (StringUtils.isNotBlank(this.getPackNo())){
            lqw.eq("gpi.pack_no" ,this.getPackNo());
        }
        if (StringUtils.isNotBlank(this.getAgentCtnNo())){
            lqw.eq("gcl.agent_ctn_no" ,this.getAgentCtnNo());
        }
        if (StringUtils.isNotBlank(this.getHoldOrNot())){
            lqw.eq(alias+"hold_or_not" ,this.getHoldOrNot());

        if (this.getChinaReleaseDate() != null){
            lqw.apply("DATE_FORMAT(ghgcr.china_release_date, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getChinaReleaseDate()) + "'");
        }

        if (this.getNigeriaReleaseDate() != null){
            lqw.apply("DATE_FORMAT(gnwr.nigeria_release_date, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getNigeriaReleaseDate()) + "'");
        }
    }
}
}
